# -*- coding:utf-8 -*-
import os
import re
import time

print('------')
# os.popen() 调用 read() 方法有返回值
def kill_c(yonghu='root',name='chrome'):
    b = os.popen('ps -aux | grep {}'.format(name)).read()
    # print(b)
    ls = b.split('\n')
    # print(ls)
    for i in ls:
        if yonghu in i:
            c = re.search('(?sm)\w*\s*(\d*)', i)
            # os.system() 运行 Linux 命令没有返回值,直接运行
            os.system('kill -9 %s' % c.group(1))
            print(c.group(1), 'kill')

if __name__ =='__main__':
    kill_c(yonghu='python kuaipai_2.py',name='python')
    # kill_c(yonghu='python redis_cache.py',name='python')
    time.sleep(5)
    kill_c()